<?php
require_once 'inc.php';

//hash_move_download_files("images.download", IMAGE_BASE_HASH_DIR);
hash_move_download_files("_ing", PAGE_BASE_HASH_DIR);

function hash_move_download_files($download_dir, $hash_base_dir)
{
	if ($handle = opendir($download_dir)) {
		while (false !== ($file = readdir($handle))) {
			if ($file != "." && $file != "..") {
				file_put_contents('imagedone.txt', $file."\n", FILE_APPEND);
				hash_move("$download_dir/$file", $hash_base_dir);
			}
		}
		closedir($handle);
	}
}

function hash_move($file, $hash_base_dir)
{
	$hash_num = intval(basename($file));
	
	$dest_dir = $hash_base_dir.'/'.floor($hash_num/HASH_NUMBER);
	try_make_dir($dest_dir);
	rename($file, $dest_dir.'/'.basename($file));
}
